home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
MacHack 1997
/
MacHack 1997.toast
/
Hacks
/
Hacks ’96
/
VideoFolder 1.0a
/
Source
/
MoreFiles 1.4.1
/
FullPath.p
< prev
next >
Wrap
Text File
|
1995-12-21
|
8KB
|
168 lines
UNIT FullPath;
{ Apple Macintosh Developer Technical Support }
{ }
{ Routines for dealing with full pathnames... if you really must. }
{ }
{ by Jim Luther, Apple Developer Technical Support Emeritus }
{ }
{ File: FullPath.p }
{ }
{ Copyright © 1995 Apple Computer, Inc. }
{ All rights reserved. }
{ }
{ You may incorporate this sample code into your applications without }
{ restriction, though the sample code has been provided "AS IS" and the }
{ responsibility for its operation is 100% yours. However, what you are }
{ not permitted to do is to redistribute the source as "DSC Sample Code" }
{ after having made changes. If you're going to re-distribute the source, }
{ we require that you make it clear in the source that the code was }
{ descended from Apple Sample Code, but that you've made changes. }
{ IMPORTANT NOTE: }
{ }
{ The use of full pathnames is strongly discouraged. Full pathnames are }
{ particularly unreliable as a means of identifying files, directories }
{ or volumes within your application, for two primary reasons: }
{ }
{ • The user can change the name of any element in the path at }
{ virtually any time. }
{ • Volume names on the Macintosh are *not* unique. Multiple }
{ mounted volumes can have the same name. For this reason, the use of }
{ a full pathname to identify a specific volume may not produce the }
{ results you expect. If more than one volume has the same name and }
{ a full pathname is used, the File Manager currently uses the first }
{ mounted volume it finds with a matching name in the volume queue. }
{ }
{ In general, you should use a file’s name, parent directory ID, and }
{ volume reference number to identify a file you want to open, delete, }
{ or otherwise manipulate. }
{ }
{ If you need to remember the location of a particular file across }
{ subsequent system boots, use the Alias Manager to create an alias }
{ record describing the file. If the Alias Manager is not available, you }
{ can save the file’s name, its parent directory ID, and the name of the }
{ volume on which it’s located. Although none of these methods is }
{ foolproof, they are much more reliable than using full pathnames to }
{ identify files. }
{ }
{ Nonetheless, it is sometimes useful to display a file’s full pathname }
{ to the user. For example, a backup utility might display a list of full }
{ pathnames of files as it copies them onto the backup medium. Or, a }
{ utility might want to display a dialog box showing the full pathname of }
{ a file when it needs the user’s confirmation to delete the file. No }
{ matter how unreliable full pathnames may be from a file-specification }
{ viewpoint, users understand them more readily than volume reference }
{ numbers or directory IDs. }
{ }
{ The following technique for constructing the full pathname of a file is }
{ intended for display purposes only. Applications that depend on any }
{ particular structure of a full pathname are likely to fail on alternate }
{ foreign file systems or under future system software versions. }
INTERFACE
USES
Files;
{***************************************************************************}
FUNCTION GetFullPath (vRefNum: INTEGER;
dirID: LONGINT;
name: StringPtr;
VAR fullPathLength: INTEGER;
VAR fullPath: Handle): OSErr;
{ Get a full pathname to a volume, directory or file. }
{ The GetFullPath function builds a full pathname to the specified }
{ object. The full pathname is returned in the newly created handle }
{ fullPath and the length of the full pathname is returned in }
{ fullPathLength. Your program is responsible for disposing of the }
{ fullPath handle. }
{ }
{ vRefNum input: Volume specification. }
{ dirID input: Directory ID. }
{ name input: Pointer to object name, or nil when dirID }
{ specifies a directory that's the object. }
{ fullPathLength output: The number of characters in the full pathname. }
{ If the function fails to create a full }
{ pathname, it sets fullPathLength to 0. }
{ fullPath output: A handle to the newly created full pathname }
{ buffer. If the function fails to create a }
{ full pathname, it sets fullPath to NULL. }
{***************************************************************************}
FUNCTION FSpGetFullPath ({CONST}VAR spec: FSSpec;
VAR fullPathLength: INTEGER;
VAR fullPath: Handle): OSErr;
{ Get a full pathname to a volume, directory or file. }
{ The GetFullPath function builds a full pathname to the specified }
{ object. The full pathname is returned in the newly created handle }
{ fullPath and the length of the full pathname is returned in }
{ fullPathLength. Your program is responsible for disposing of the }
{ fullPath handle. }
{ }
{ spec input: An FSSpec record specifying the object. }
{ fullPathLength output: The number of characters in the full pathname. }
{ If the function fails to create a full }
{ pathname, it sets fullPathLength to 0. }
{ fullPath output: A handle to the newly created full pathname }
{ buffer. If the function fails to create a }
{ full pathname, it sets fullPath to NULL. }
{***************************************************************************}
FUNCTION FSpLocationFromFullPath (fullPathLength: INTEGER;
fullPath: Ptr;
VAR spec: FSSpec): OSErr;
{ Get a FSSpec from a full pathname. }
{ The FSpLocationFromFullPath function returns a FSSpec to the object }
{ specified by full pathname. This function requires the Alias Manager. }
{ }
{ fullPathLength input: The number of characters in the full pathname }
{ of the target. }
{ fullPath input: A pointer to a buffer that contains the full }
{ pathname of the target. The full pathname }
{ starts with the name of the volume, includes }
{ all of the directory names in the path to the }
{ target, and ends with the target name. }
{ spec output: An FSSpec record specifying the object. }
{***************************************************************************}
FUNCTION LocationFromFullPath (fullPathLength: INTEGER;
fullPath: Ptr;
VAR vRefNum: INTEGER;
VAR parID: LONGINT;
VAR name: Str31): OSErr;
{ Get a FSSpec from a full pathname. }
{ The FSpLocationFromFullPath function returns a FSSpec to the object }
{ specified by full pathname. This function requires the Alias Manager. }
{ }
{ fullPathLength input: The number of characters in the full pathname }
{ of the target. }
{ fullPath input: A pointer to a buffer that contains the full }
{ pathname of the target. The full pathname }
{ starts with the name of the volume, includes }
{ all of the directory names in the path to the }
{ target, and ends with the target name. }
{ vRefNum output: The volume reference number. }
{ parID output: The parent directory ID of the specified object.}
{ name output: The name of the specified object. }
{***************************************************************************}
IMPLEMENTATION
END.